﻿#include <stdio.h>
#include "source/ff.h"

static FATFS disk1_fs;			// 针对disk1.vhd
static FATFS disk2_fs;			// 针对disk2.vhd

int main()
{
	// 挂载文件系统
	FRESULT res = f_mount(&disk1_fs, "0:", 1);
	if (res != FR_OK) {
		printf("mount disk1 failed.");
		return -1;
	}

	// 挂载文件系统
	res = f_mount(&disk2_fs, "1:", 1);
	if (res != FR_OK) {
		printf("mount disk2 failed.");
		return -1;
	}
	
	// SFN + LFN
	// SFN: 8 + EXT(3)
	// LFN
	FIL file;
	res = f_open(&file, "0:/历史.html", FA_READ);
	if (res != FR_OK) {
		printf("open file error.\n");
		return -1;
	}

	while (1) {
		static char read_buf[1024];
		UINT read_size;
		res = f_read(&file, read_buf, sizeof(read_buf) - 1, &read_size);
		if (res != FR_OK) {
			printf("\n ------ read error ---------\n");
			break;
		}
		read_buf[sizeof(read_buf) - 1] = '\0';
		read_buf[read_size] = '\0';
		printf("%s", read_buf);

		if (read_size < sizeof(read_buf) - 1) {
			printf("\n ------ read complete ---------\n");
			break;
		}
	}

	f_close(&file);

	printf("Hello, world.\n");
    return 0;
}
